<?php
/*
 * 手机客户端 执行或取消关注
 * 传入参数 
 * 2013-12-24
 */
include "inc/public_header.php";
include "func/user.php";				//用户信息处理函数

//获取用户信息
$uInfoArr = user_getInfoFromUUID();
if(!$uInfoArr){
	echo json_encode(array("success"=>"0","errCode"=>"0","msg"=>"没有获取到用户信息"));
	die;
}
$uid 			= $uInfoArr["uid"];				//用户信息主键
 
$ouid			= $_REQUEST["userId"]; 			//目标用户主键
$hd_id			= $_REQUEST["hd_id"];			//活动主键

$reJson = array();//构建返回值

if(!isset($ouid) || $ouid==""){
	echo json_encode(array("success"=>"0","msg"=>"没有获取到目标用户主键"));
	die;
}
if($uid==$ouid){
	echo json_encode(array("success"=>"2","msg"=>"自己不能关注自己"));
	die;
}

//查询是否存在关注记录
$sql = "select id from new_weituo_fensi where fuid='".$uid."' and uid='".$ouid."' and hd_id='".$hd_id."'";
$db->query($sql);
if($db->next_record()){
	//取消关注
	$type = "2";
	$sql = "delete from new_weituo_fensi where id='".$db->f("id")."' and hd_id='".$hd_id."'";
}else{
	//新增关注
	$type = "1";
	$sql = "insert into new_weituo_fensi (fuid,uid,ctime,hd_id) values('".$uid."','".$ouid."',now(),'".$hd_id."')";
}
$db->query($sql);

echo json_encode(array(
						 "success"	=>	"1"
						,"ouid"		=>	$ouid	//目标用户主键
						,"hd_id"	=>	$hd_id	//活动主键
						,"type"=>$type));		//操作类型，1新增关注  2取消关注

?>